﻿/*-------------------------------------------------------------------------
* 命名空间: PrismDialogSimple.ViewModels/PrismDialogViewModel
* 类       名: PrismDialogViewModel
* 功      能:  TD
* 时      间:  2023/12/22 14:55:40
* 版      本:  V1.0
* 作      者:  Fioman
* 格      言:  Talk is cheap,show me the code ^_^
*-------------------------------------------------------------------------*/
using Prism.Commands;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PrismDialogSimple.ViewModels
{
    /// <summary>
    /// 在Prism的框架中,我们通常在视图模型ViewModel中实现IDialogAware接口,而不是在视图View中实现.
    /// 这是因为按照MVVM(Model-View-ViewModel)架构的设计原则,视图模型负责处理应用程序逻辑部分,而视图则
    /// 只是展示用户界面.当然,Prism也是允许你在视图中实现IDialogAware接口的,但是通常不是推荐的写法.
    /// </summary>
    public class PrismDialogViewModel : IDialogAware
    {
        public PrismDialogViewModel()
        {
            ConfirmCommand = new DelegateCommand(() =>
            {
                DialogParameters parameters = new DialogParameters()
                {
                    { "Value",Title},
                };

                RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parameters));
            });

            CancelComand = new DelegateCommand(() =>
            {
                DialogParameters parameters = new DialogParameters
                {
                    {"Value",Title},
                };
                RequestClose?.Invoke(new DialogResult(ButtonResult.No));
            });


        }

        public DelegateCommand ConfirmCommand { get; private set; }
        public DelegateCommand CancelComand { get; private set; }

        public string? Title { get; set; }

        public event Action<IDialogResult>? RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }

        public void OnDialogClosed()
        {

        }

        public void OnDialogOpened(IDialogParameters parameters)
        {

        }
    }
}
